import { useEffect, useState } from 'react';

const useGetData = (url, flag_req) => {

    const [bill_data, setBillData] = useState([]);
    const [categories_data, setCategoriesData] = useState([]);

    useEffect(() => {
        fetch(url, {
            body: { code: {} },
            method: 'POST'
        })
            .then(res => res.json())
            .then(result => {
                if (result.length) {
                    setBillData(result[0]);
                    setCategoriesData(result[1]);
                }
            })
            .catch(er => console.info('error', er))
    }, [url, flag_req]);

    return [bill_data, categories_data];
};

export default useGetData;